package com.anhry.www.safety.manage.djpd.struts.action;

import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.anhry.www.safety.manage.djpd.bean.TbDjpdApply;
import com.anhry.www.safety.manage.djpd.bean.TbDjpdApplyItem;
import com.anhry.www.safety.manage.djpd.bean.TbDjpdApplyWs1;
import com.anhry.www.safety.manage.djpd.bean.TbDjpdApplyWs2;
import com.anhry.www.safety.manage.djpd.bean.TbDjpdCheck;
import com.anhry.www.safety.manage.djpd.bean.TbDjpdItemView;
import com.anhry.www.safety.manage.djpd.bean.TbDjpdTab;
import com.anhry.www.safety.manage.djpd.struts.base.DjpdBaseAction;
import com.anhry.www.safety.manage.enterprise.bean.TbCorpInfo;
import com.anhry.www.safety.manage.system.bean.TbUser;
import com.anhry.www.safety.util.Constants;
import com.anhry.www.safety.util.DateFormater;
import com.anhry.www.safety.util.Loggers;
import com.anhry.www.safety.util.Util;

/**
 * @date:2012-11-1
 * @remark:
 * @author:dongbin
 */

@Controller
@Scope("prototype")
@SuppressWarnings("unchecked")
public class DjpdAction extends DjpdBaseAction{
	
	private Logger logger = Logger.getLogger(DjpdAction.class);

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String objId;
	private List itemList;
	private TbDjpdTab tab;
	private String[] itemIds;
	private String[] itemChecks;
	private String[] zpScore;
	private String[] zpKfMsg;
	private String[] zpHg;
	private String[] zpBhg;
	private String[] zpBsj;
	private TbDjpdApply apply;
	private String isSubmit;
	private Date nowDate;
	private TbDjpdApplyWs1 ws1;
	private TbDjpdApplyWs2 ws2;
	private String wsId;
	private String corpName;
	private String corpAdds;
	private String corpFr;
	private String corpTel;
	private String corpPost;
	private String corpPer;
	private String corpPerTel;
	private String corpPerPhone;
	private String corpPerFax;
	private String corpPerMail;
	private String corpAqUnit;
	private String corpAqPer;
	private String corpHy;
	private String corpAqCode;
	private String corpZhce;
	private String corpChanpin;
	private String corpCyrs;
	private String corpSnxse;
	private String addYear;
	private String addMonth;
	private String addDay;
	private String corpFax;
	private String zpByear;
	private String zpBmonth;
	private String zpBday;
	private String zpEyear;
	private String zpEmonth;
	private String zpEday;
	private String zpInfo;
	private String zpBdate;
	private String zpEdate;
	private String zpLeader;//组长
	private String zpZyuan;//组员
	private String cType;
	private String cType1;
	private String export;
	private List objList;
	private int isSuanfei;//是否算分
	private boolean citySupervision; //是否市直管
	private boolean review; //复评
	private TbDjpdCheck check;
	private Integer checkRole; //抽查角色 1：县（市，区）安办 2：市安办
	/**
	 * 等级评定首页
	 * @return
	 */
	public String index(){
		try {
			TbCorpInfo sessioncorp = (TbCorpInfo)this.contextPvd.getSessionAttr(Util.SESSION_CORPUSER);
			TbCorpInfo corp = (TbCorpInfo)this.utilService.getObjectById(TbCorpInfo.class, sessioncorp.getId());
			if(Constants.CITY_SUPERVISION.equals(corp.getCorpLixu())) {
				citySupervision = true;
			} else {
				citySupervision = false;
			}
			this.setNowDate(DateFormater.dateFormatDate(new Date()));
			if(corp.getDjpdFpDate() != null) {
				if(nowDate.after(corp.getDjpdFpDate())) {
					review = true;
				}
			}
			if(null!=corp.getDjpdId() && corp.getDjpdId()>0){
				TbDjpdApply app = (TbDjpdApply)this.utilService.getObjectById(TbDjpdApply.class, corp.getDjpdId());
				if(null!=app){
					this.setApply(app);
				}
			}
			this.setResult("index");
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("DjpdAction index() 异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 进入评级页面
	 * @return
	 */
	public String fjpdEdit(){
		try {
			TbCorpInfo sessioncorp = (TbCorpInfo)this.contextPvd.getSessionAttr(Util.SESSION_CORPUSER);
			TbCorpInfo corp = (TbCorpInfo)this.utilService.getObjectById(TbCorpInfo.class, sessioncorp.getId());
			TbDjpdTab tab = null;
			Calendar ca = Calendar.getInstance();
			Date date = DateFormater.calenderParseDate(ca);
			if(null!=corp.getDjpdId() && corp.getDjpdId()>0){
				TbDjpdApply app = (TbDjpdApply)this.utilService.getObjectById(TbDjpdApply.class, corp.getDjpdId());
				if(null!=app){
					if("0".equals(app.getApplyStatus()) || "1".equals(app.getApplyStatus()) 
							|| "2".equals(app.getApplyStatus()) || "3".equals(app.getApplyStatus()) || "5".equals(app.getApplyStatus())){//未提交或者打回
						this.setApply(app);
						this.setItemList((List)this.utilService.getHqlQuery("from TbDjpdApplyItem t where 1=1 and t.applyId="+app.getId()+" order by t.id"));
					}else if("7".equals(app.getApplyStatus()) || "10".equals(app.getApplyStatus())){//已确认的评级记录
						if(date.after(app.getFpDate())){//如果当前时间在复评时间之后，那么该复评了
							if(null!=sessioncorp.getTbCorpTypeMin().getDjpdTabId()){
								tab = (TbDjpdTab)this.utilService.getObjectById(TbDjpdTab.class, sessioncorp.getTbCorpTypeMin().getDjpdTabId());
								if(null!=tab){
									TbDjpdApply obj = new TbDjpdApply();
									obj = this.initApply(obj);
									obj.setCorpId(corp.getId());
									obj.setTabId(tab.getId());
									obj.setTabName(tab.getTabName());
									this.utilService.save(obj);
									corp.setDjpdId(obj.getId());
									this.utilService.update(corp);
									this.setApply(obj);
									this.setItemList(this.initItemList(obj,tab));
								}
							}
						}else{
							this.setTip("您已经进行了等级评定自评！");
							return this.index();
						}
					}else{
						this.setTip("您已经进行了等级评定自评！");
						return this.index();
					}
				}
			}else{
				if(null!=sessioncorp.getTbCorpTypeMin().getDjpdTabId()){
					tab = (TbDjpdTab)this.utilService.getObjectById(TbDjpdTab.class, sessioncorp.getTbCorpTypeMin().getDjpdTabId());
					if(null!=tab){
						TbDjpdApply obj = new TbDjpdApply();
						obj = this.initApply(obj);
						obj.setCorpId(corp.getId());
						obj.setTabId(tab.getId());
						obj.setTabName(tab.getTabName());
						this.utilService.save(obj);
						corp.setDjpdId(obj.getId());
						this.utilService.update(corp);
						this.setApply(obj);
						this.setItemList(this.initItemList(obj,tab));
					}
				}
			}
			this.setResult("djpd_edit");
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("DjpdAction index() 异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 初始化评分项目列表（方法废弃 2012-11-07 dongbin）
	 * @param tab
	 * @param itemList
	 * @return
	 */
	public List initBzhList(TbDjpdTab tab,List<TbDjpdApplyItem> itemList){
		List<TbDjpdItemView> list = null;
		try {
			list = (List)this.utilService.getHqlQuery("from TbDjpdItemView t where 1=1 and t.tabId="+tab.getId()+" order by itemType1,itemType2,id");
			if(null!=itemList && itemList.size()>0 && null!=list && list.size()>0){
				for(TbDjpdItemView bzh : list){
					for(TbDjpdApplyItem item : itemList){
						if(item.getItemId().toString().equals(bzh.getId().toString())){
							bzh.setPjId(item.getId());
							bzh.setPjCheck(item.getZpIsCheck());
							bzh.setPjScore(item.getZpScore());
							bzh.setPjKfMsg(item.getZpKfMsg());
						}
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("DjpdAction initBzhList() 异常："+e.getMessage());
		}
		return list;
	}
	
	/**
	 * 初始化评级细目
	 * @param obj
	 * @param tab
	 * @return
	 */
	public List initItemList(TbDjpdApply obj,TbDjpdTab tab){
		List itemList = null;
		try {
			TbCorpInfo corp = (TbCorpInfo)this.contextPvd.getSessionAttr(Util.SESSION_CORPUSER);
			List<TbDjpdItemView> list = (List)this.utilService.getHqlQuery("from TbDjpdItemView t where 1=1 and t.tabId="+tab.getId()+" order by itemType1,itemType2,id");
			if(null!=list && list.size()>0){
				for(TbDjpdItemView bzh : list){
					TbDjpdApplyItem item = new TbDjpdApplyItem();
					item.setApplyId(obj.getId());
					item.setCorpId(corp.getId());
					item.setIsDele("0");
					item.setItemBzh(bzh.getItemBzh());
					item.setItemId(bzh.getId());
					item.setItemInfo(bzh.getItemInfo());
					item.setItemScore(bzh.getItemScore());
					item.setItemType1(bzh.getItemType1());
					item.setItemType1Name(bzh.getItemType1Name());
					item.setItemType2(bzh.getItemType2());
					item.setItemType2Name(bzh.getItemType2Name());
					item.setItemType3(bzh.getItemType3());
					this.utilService.save(item);
				}
				itemList = (List)this.utilService.getHqlQuery("from TbDjpdApplyItem t where 1=1 and t.applyId="+obj.getId()+" order by t.id"); 
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("DjpdAction List initItemList(TbDjpdApply obj,TbDjpdTab tab)异常："+e.getMessage());
		}
		return itemList;
	}
	
	/**
	 * 初始化评级
	 * @param obj
	 * @return
	 */
	public TbDjpdApply initApply(TbDjpdApply obj){
		obj.setApplyChecks(0);
		obj.setApplyStatus("0");
		obj.setIsDele("0");
		obj.setZpBhgNum(0);
		obj.setZpBsjNum(0);
		obj.setZpHgNum(0);
		obj.setZpJchScore(0);
		obj.setZpScore(0);
		obj.setZpXchScore(0);
		return obj;
	}
	
	/**
	 * 评分保存
	 * @return
	 */
	public String zpSave(){
		try {
			TbCorpInfo sessioncorp = (TbCorpInfo)this.contextPvd.getSessionAttr(Util.SESSION_CORPUSER);
			TbCorpInfo corp = (TbCorpInfo)this.utilService.getObjectById(TbCorpInfo.class, sessioncorp.getId());
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApply obj = (TbDjpdApply)this.utilService.getObjectById(TbDjpdApply.class, Long.parseLong(this.objId));
				if(null!=obj){
					if("2".equals(this.isSubmit)){
						obj.setApplyStatus("1");
					}else{
						obj.setApplyStatus("0");
					}
					if(null!=this.zpHg && this.zpHg.length>0){
						obj.setZpHgNum(this.zpHg.length);
					}
					if(null!=this.zpBhg && this.zpBhg.length>0){
						obj.setZpBhgNum(this.zpBhg.length);
					}
					if(null!=this.zpBsj && this.zpBsj.length>0){
						obj.setZpBsjNum(this.zpBsj.length);
					}
					if(null!=this.itemIds && this.itemIds.length>0){
						for(int i=0;i<this.itemIds.length;i++){
							TbDjpdApplyItem item = (TbDjpdApplyItem)this.utilService.getObjectById(TbDjpdApplyItem.class, Long.parseLong(this.itemIds[i]));
							item.setZpIsCheck(this.itemChecks[i]);
							item.setZpKfMsg(this.zpKfMsg[i]);
							if(null!=this.zpScore[i] && this.zpScore[i].length()>0){
								item.setZpScore(Integer.parseInt(this.zpScore[i]));
							}else{
								item.setZpScore(null);
							}
							this.utilService.update(item);
						}
					}
					if("1".equals(this.isSubmit) || "2".equals(this.isSubmit)){
						String sumsql = "select sum(case when t.zp_is_check=3 then 0 when t.zp_is_check=2 and t.zp_score is null then 0 when t.zp_is_check is null then 0 else t.zp_score end) " +
								"from tb_djpd_apply_item t where t.apply_id="+obj.getId();//总分
						String bsjsql = "select sum(t.item_score) from tb_djpd_apply_item t where t.zp_is_check=3 and t.apply_id="+obj.getId();//不涉及项分数
						String jchsql = "select sum(case when t.zp_is_check=3 then 0 when t.zp_is_check=2 and t.zp_score is null then 0 when " +
								"t.zp_is_check is null then 0 else t.zp_score end) from tb_djpd_apply_item t where t.item_type1=1 and t.apply_id="+obj.getId();//基础
						String xchsql = "select sum(case when t.zp_is_check=3 then 0 when t.zp_is_check=2 and t.zp_score is null then 0 when " +
								"t.zp_is_check is null then 0 else t.zp_score end) from tb_djpd_apply_item t where t.item_type1=2 and t.apply_id="+obj.getId();//现场
						int totalScore = Integer.parseInt(this.utilService.getObjectBySql(sumsql));
						int excludeScore = Integer.parseInt(this.utilService.getObjectBySql(bsjsql));
						int basicScore = Integer.parseInt(this.utilService.getObjectBySql(jchsql));
						int presentScore = Integer.parseInt(this.utilService.getObjectBySql(xchsql));
						
						obj.setZpJchScore(basicScore);
						obj.setZpXchScore(presentScore);
						//企业自评得分 = 自评总分*1000/（1000-不涉及总分）-----国家的标准化是这么算的

						Double df = Double.valueOf(totalScore *1000/Double.valueOf(1000-excludeScore)) ;
						if(logger.isDebugEnabled()) {
							logger.debug("totalScore ======> " + totalScore);
							logger.debug("excludeScore ======> " + excludeScore);
							logger.debug("basicScore ======> " + basicScore);
							logger.debug("presentScore ======> " + presentScore);
							
							logger.debug("Corp final score is ------> " + df);
						}
						DecimalFormat dft = new DecimalFormat("0") ;
						String tem = dft.format(df);
						int score = Integer.parseInt(tem);
						obj.setZpScore(score);
						obj.setZpDate(new Date());
						String gradeDj = "";
						if(score>=900){gradeDj = "A";}
						if(score>=700 && score<900){gradeDj = "B";}
						if(score>=600 && score<700){gradeDj = "C";}
						if(score<600){gradeDj = "D";}
						obj.setZpGrade(gradeDj);
						Calendar ca = Calendar.getInstance();
						ca.add(Calendar.YEAR,+1);
						corp.setDjpdFpDate(DateFormater.calenderParseDate(ca));
						obj.setFpDate(DateFormater.calenderParseDate(ca));
						this.utilService.update(corp);
					}
					this.utilService.update(obj);
					this.setTip("操作成功");
					if("2".equals(this.isSubmit)){
						return this.fjpdWs1();
					}
					return this.fjpdEdit();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("DjpdAction zpSave() 异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 填写申请表
	 * @return
	 */
	public String fjpdWs1(){
		try {
			TbCorpInfo corp = (TbCorpInfo)this.contextPvd.getSessionAttr(Util.SESSION_CORPUSER);
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApplyWs1 ws1 = this.djpdService.getDjpdWs1(this.objId);
				if(null!=ws1){
					this.setWs1(ws1);
				}else{
					TbDjpdApplyWs1 ws = new TbDjpdApplyWs1();
					ws.setApplyId(Long.parseLong(this.objId));
					ws.setCorpAdds(corp.getCorpRegAddress());
					ws.setCorpAqCode(corp.getCorpXkCode());
					ws.setCorpAqPer(corp.getSafetyHead());
					ws.setCorpAqUnit("");
					ws.setCorpChanpin(corp.getCorpChanpin());
					ws.setCorpCyrs(corp.getCorpCyrs()+"");
					ws.setCorpFr(corp.getCorpFr());
					ws.setCorpName(corp.getCorpName());
					ws.setCorpPost(corp.getCorpPost());
					ws.setIsDele("0");
					this.utilService.save(ws);
					this.setWs1(ws);
				}
				this.setResult("djpd_ws1");
				return SUCCESS;
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("DjpdAction djpdWs1() 异常："+e.getMessage());
		}
		return ERROR;
	}
	/**
	 * 自评报告
	 * @return
	 */
	public String fjpdWs2(){
		try {
			TbCorpInfo corp = (TbCorpInfo)this.contextPvd.getSessionAttr(Util.SESSION_CORPUSER);
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApplyWs2 ws2 = this.djpdService.getDjpdWs2(this.objId);
				if(null!=ws2){
					this.setWs2(ws2);
				}else{
					TbDjpdApplyWs2 ws = new TbDjpdApplyWs2();
					ws.setApplyId(Long.parseLong(this.objId));
					ws.setCorpAdds(corp.getCorpRegAddress());
					ws.setCorpName(corp.getCorpName());
					ws.setCorpPost(corp.getCorpPost());
					ws.setCorpTel(corp.getCorpPhone());
					this.utilService.save(ws);
					this.setWs2(ws);
				}
				this.setResult("djpd_ws2");
				return SUCCESS;
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("DjpdAction djpdWs1() 异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 申请表保存
	 * @return
	 */
	public String fjpdWs1Save(){
		try {
			if(null!=this.wsId && this.wsId.length()>0){
				TbDjpdApplyWs1 ws = (TbDjpdApplyWs1)this.utilService.getObjectById(TbDjpdApplyWs1.class, Long.parseLong(this.wsId));
				if(null!=ws){
					ws.setCorpAdds(corpAdds);
					ws.setCorpAqCode(corpAqCode);
					ws.setCorpAqPer(corpAqPer);
					ws.setCorpAqUnit(corpAqUnit);
					ws.setCorpChanpin(corpChanpin);
					ws.setCorpCyrs(corpCyrs);
					ws.setCorpFr(corpFr);
					ws.setCorpName(corpName);
					ws.setCorpPost(corpPost);
					ws.setAddDay(addDay);
					ws.setAddMonth(addMonth);
					ws.setAddYear(addYear);
					ws.setCorpHy(corpHy);
					ws.setCorpPer(corpPer);
					ws.setCorpPerFax(corpPerFax);
					ws.setCorpPerMail(corpPerMail);
					ws.setCorpPerPhone(corpPerPhone);
					ws.setCorpPerTel(corpPerTel);
					ws.setCorpPost(corpPost);
					ws.setCorpSnxse(corpSnxse);
					ws.setCorpTel(corpTel);
					ws.setCorpZhce(corpZhce);
					ws.setWsDate(new Date());
					this.utilService.update(ws);
					TbDjpdApply obj = (TbDjpdApply)this.utilService.getObjectById(TbDjpdApply.class, Long.parseLong(this.objId));
					if(null!=obj){
						obj.setApplyStatus("2");
						this.utilService.update(obj);
					}
					this.setTip("操作成功！");
					return this.fjpdWs2();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("fjpdAction fjpdWs1Save() 异常："+e.getMessage());
		}
		return ERROR;
	}
	/**
	 * 自评报告保存
	 * @return
	 */
	public String fjpdWs2Save(){
		try {
			if(null!=this.wsId && this.wsId.length()>0){
				TbDjpdApplyWs2 ws = (TbDjpdApplyWs2)this.utilService.getObjectById(TbDjpdApplyWs2.class, Long.parseLong(this.wsId));
				if(null!=ws){
					ws.setCorpAdds(corpAdds);
					ws.setCorpFax(corpFax);
					ws.setCorpName(corpName);
					ws.setCorpPost(corpPost);
					ws.setCorpTel(corpTel);
					ws.setWsDate(new Date());
					if(null!=this.zpBdate && this.zpBdate.length()>0){
						ws.setZpBdate(DateFormater.formatDate(this.zpBdate));
					}
					if(null!=this.zpEdate && this.zpEdate.length()>0){
						ws.setZpEdate(DateFormater.formatDate(this.zpEdate));
					}
					ws.setZpInfo(zpInfo);
					ws.setZpLeader(zpLeader);
					ws.setZpZyuan(zpZyuan);
					this.utilService.update(ws);
					TbDjpdApply obj = (TbDjpdApply)this.utilService.getObjectById(TbDjpdApply.class, Long.parseLong(this.objId));
					if(null!=obj){
						TbCorpInfo corp = (TbCorpInfo)this.utilService.getObjectById(TbCorpInfo.class, obj.getCorpId());
						if(Constants.CITY_SUPERVISION.equals(corp.getCorpLixu())) {
							citySupervision = true;
							obj.setApplyStatus("20");
						} else {
							citySupervision = false;
							obj.setApplyStatus("3");
						}
						
						this.utilService.update(obj);
					}
					return this.fjpdSuccess();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("fjpdAction fjpdWs1Save() 异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 评级页面，在该页面中下载申请表和自评报告
	 * @return
	 */
	public String fjpdSuccess(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApply obj = (TbDjpdApply)this.utilService.getObjectById(TbDjpdApply.class, Long.parseLong(this.objId));
				TbCorpInfo corp = (TbCorpInfo)this.utilService.getObjectById(TbCorpInfo.class, obj.getCorpId());
				if(Constants.CITY_SUPERVISION.equals(corp.getCorpLixu())) {
					citySupervision = true;
				} else {
					citySupervision = false;
				}
				if(null!=obj){
					this.setApply(obj);
					TbDjpdApplyWs1 ws1 = this.djpdService.getDjpdWs1(this.objId);
					TbDjpdApplyWs2 ws2 = this.djpdService.getDjpdWs2(this.objId);
					this.setWs1(ws1);
					this.setWs2(ws2);
					this.setResult("djpd_success");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("fjpdAction fjpdSuccess() 异常："+e.getMessage());
		}
		return SUCCESS;
	}
	/**
	 * 提交属地部门
	 * @return
	 */
	public String fjpdSuccSave(){
		try {
			TbCorpInfo corp = (TbCorpInfo)this.contextPvd.getSessionAttr(Util.SESSION_CORPUSER);
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApply obj = (TbDjpdApply)this.utilService.getObjectById(TbDjpdApply.class, Long.parseLong(this.objId));
				if(null!=obj){
					if(Constants.CITY_SUPERVISION.equals(corp.getCorpLixu())){
						obj.setApplyStatus("6");//直接提交行业部门
						obj.setSdType("2");
					}else{
						obj.setApplyStatus("4");
						obj.setSdType("1");
					}
					this.utilService.update(obj);
					return this.index();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("DjpdAction djpdSuccess() 异常："+e.getMessage());
		}
		return SUCCESS;
	}
	
	/**
	 * 等级评定结果查看
	 * @return
	 */
	public String fjpdShow(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApply obj = (TbDjpdApply)this.utilService.getObjectById(TbDjpdApply.class, Long.parseLong(this.objId));
				if(null!=obj){
					this.setApply(obj);
					StringBuilder hql = new StringBuilder("from TbDjpdApplyItem t where 1=1 and t.applyId="+obj.getId()+" ");
					if(null!=this.cType && this.cType.length()>0){
						hql.append(" and t.zpIsCheck="+this.cType);
					}
					hql.append(" order by t.id");
					this.setItemList((List)this.utilService.getHqlQuery(hql.toString()));
					TbDjpdApplyWs1 ws1 = this.djpdService.getDjpdWs1(this.objId);
					TbDjpdApplyWs2 ws2 = this.djpdService.getDjpdWs2(this.objId);
					this.setWs1(ws1);
					this.setWs2(ws2);
					this.setResult("djpd_show");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("DjpdAction djpdShow() 异常："+e.getMessage());
		}
		return SUCCESS;
	}
	
	/**
	 * 申请书和自评/评估报告
	 * @return
	 */
	public String fjpdWsShow(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				if("1".equals(this.cType)){
					TbDjpdApplyWs1 ws1 = this.djpdService.getDjpdWs1(this.objId);
					if(null!=ws1){
						this.setWs1(ws1);
					}
					if("word".equals(this.export)){
						this.setResult("djpd_ws1_word");
					}else{
						this.setResult("djpd_ws1_show");
					}
					return SUCCESS;
				}
				if("2".equals(this.cType)){
					TbDjpdApplyWs2 ws2 = this.djpdService.getDjpdWs2(this.objId);
					if(null!=ws2){
						this.setWs2(ws2);
					}
					if("word".equals(this.export)){
						this.setResult("djpd_ws2_word");
					}else{
						this.setResult("djpd_ws2_show");
					}
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("DjpdAction djpdWsShow() 异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 等级评定乡镇初审结果
	 * @return
	 */
	public String fjpdSdShow(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApply obj = (TbDjpdApply)this.utilService.getObjectById(TbDjpdApply.class, Long.parseLong(this.objId));
				TbCorpInfo corp = (TbCorpInfo)this.utilService.getObjectById(TbCorpInfo.class, obj.getCorpId());
				if(Constants.CITY_SUPERVISION.equals(corp.getCorpLixu())) {
					citySupervision = true;
				} else {
					citySupervision = false;
				}
				if(null!=obj){
					this.setApply(obj);
					StringBuilder hql = new StringBuilder("from TbDjpdApplyItem t where 1=1 and t.applyId="+obj.getId()+" ");
					if(null!=this.cType && this.cType.length()>0){
						hql.append(" and t.zpIsCheck="+this.cType);
					}
					if(null!=this.cType1 && this.cType1.length()>0){
						hql.append(" and t.sdIsCheck="+this.cType1);
					}
					hql.append(" order by t.id");
					this.setItemList((List)this.utilService.getHqlQuery(hql.toString()));
					this.setResult("djpd_sd_show");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("DjpdAction djpdSdShow() 异常："+e.getMessage());
		}
		return SUCCESS;
	}
	
	/**
	 * 复核确认查看
	 * @return
	 */
	public String fjpdHyShow(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApply app = (TbDjpdApply)this.utilService.getObjectById(TbDjpdApply.class, Long.parseLong(this.objId));
				if(null!=app){
					this.setApply(app);
					List list = (List)this.utilService.getHqlQuery("from TbDjpdHyCheck t where 1=1 and t.applyId="+app.getId()+" order by t.id");
					if(null!=list && list.size()>0){
						this.setObjList(list);
					}
					this.setResult("djpd_hy_show");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdAction:djpdHyShow()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 中介结构确认信息
	 * @return
	 */
	public String fjpdPsdwShow(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApply app = (TbDjpdApply)this.utilService.getObjectById(TbDjpdApply.class, Long.parseLong(this.objId));
				if(null!=app){
					this.setApply(app);
					this.setResult("djpd_psdw_show");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:djpdPsdwShow()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 历史评级记录
	 * @return
	 */
	public String fjpdHis(){
		try {
			TbCorpInfo corp = (TbCorpInfo)this.contextPvd.getSessionAttr(Util.SESSION_CORPUSER);
			this.setObjList((List)this.utilService.getHqlQuery("from TbDjpdApply t where 1=1 and t.corpId="+corp.getId()+" order by t.id desc"));
			this.setResult("djpd_list");
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("DjpdAction djpdHis() 异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/*新增
	 * 何桂芳
	 * 抽查结果查看
	 */
	public String fjpdCheckShow(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApply app = (TbDjpdApply)this.utilService.getObjectById(TbDjpdApply.class, Long.parseLong(this.objId));
				if(null!=app){
					this.setApply(app);
					StringBuilder hql = new StringBuilder("from TbDjpdCheck t where 1=1 and t.applyId="+app.getId());
					hql.append(" and t.checkDept= '"+cType);
					hql.append("' order by t.id");
					List list = (List)this.utilService.getHqlQuery(hql.toString());
					if(list==null || list.size()==0){
						this.setCheck(null);
					}else{
					    this.setCheck((TbDjpdCheck)list.get(0));
					}
					this.setResult("djpd_check_show");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:fjpdCheckShow()异常："+e.getMessage());
		}
		return ERROR;
	}

	public String getObjId() {
		return objId;
	}

	public void setObjId(String objId) {
		this.objId = objId;
	}

	public List getItemList() {
		return itemList;
	}

	public void setItemList(List itemList) {
		this.itemList = itemList;
	}

	public TbDjpdTab getTab() {
		return tab;
	}

	public void setTab(TbDjpdTab tab) {
		this.tab = tab;
	}

	public String[] getItemChecks() {
		return itemChecks;
	}

	public void setItemChecks(String[] itemChecks) {
		this.itemChecks = itemChecks;
	}

	public String[] getItemIds() {
		return itemIds;
	}

	public void setItemIds(String[] itemIds) {
		this.itemIds = itemIds;
	}

	public String[] getZpScore() {
		return zpScore;
	}

	public void setZpScore(String[] zpScore) {
		this.zpScore = zpScore;
	}

	public String[] getZpBhg() {
		return zpBhg;
	}

	public void setZpBhg(String[] zpBhg) {
		this.zpBhg = zpBhg;
	}

	public String[] getZpBsj() {
		return zpBsj;
	}

	public void setZpBsj(String[] zpBsj) {
		this.zpBsj = zpBsj;
	}

	public String[] getZpHg() {
		return zpHg;
	}

	public void setZpHg(String[] zpHg) {
		this.zpHg = zpHg;
	}

	public String[] getZpKfMsg() {
		return zpKfMsg;
	}

	public void setZpKfMsg(String[] zpKfMsg) {
		this.zpKfMsg = zpKfMsg;
	}

	public TbDjpdApply getApply() {
		return apply;
	}

	public void setApply(TbDjpdApply apply) {
		this.apply = apply;
	}

	public String getIsSubmit() {
		return isSubmit;
	}

	public void setIsSubmit(String isSubmit) {
		this.isSubmit = isSubmit;
	}

	public Date getNowDate() {
		return nowDate;
	}

	public void setNowDate(Date nowDate) {
		this.nowDate = nowDate;
	}

	public TbDjpdApplyWs1 getWs1() {
		return ws1;
	}

	public void setWs1(TbDjpdApplyWs1 ws1) {
		this.ws1 = ws1;
	}

	public TbDjpdApplyWs2 getWs2() {
		return ws2;
	}

	public void setWs2(TbDjpdApplyWs2 ws2) {
		this.ws2 = ws2;
	}

	public String getAddDay() {
		return addDay;
	}

	public void setAddDay(String addDay) {
		this.addDay = addDay;
	}

	public String getAddMonth() {
		return addMonth;
	}

	public void setAddMonth(String addMonth) {
		this.addMonth = addMonth;
	}

	public String getAddYear() {
		return addYear;
	}

	public void setAddYear(String addYear) {
		this.addYear = addYear;
	}

	public String getCorpAdds() {
		return corpAdds;
	}

	public void setCorpAdds(String corpAdds) {
		this.corpAdds = corpAdds;
	}

	public String getCorpAqCode() {
		return corpAqCode;
	}

	public void setCorpAqCode(String corpAqCode) {
		this.corpAqCode = corpAqCode;
	}

	public String getCorpAqPer() {
		return corpAqPer;
	}

	public void setCorpAqPer(String corpAqPer) {
		this.corpAqPer = corpAqPer;
	}

	public String getCorpAqUnit() {
		return corpAqUnit;
	}

	public void setCorpAqUnit(String corpAqUnit) {
		this.corpAqUnit = corpAqUnit;
	}

	public String getCorpChanpin() {
		return corpChanpin;
	}

	public void setCorpChanpin(String corpChanpin) {
		this.corpChanpin = corpChanpin;
	}

	public String getCorpCyrs() {
		return corpCyrs;
	}

	public void setCorpCyrs(String corpCyrs) {
		this.corpCyrs = corpCyrs;
	}

	public String getCorpFax() {
		return corpFax;
	}

	public void setCorpFax(String corpFax) {
		this.corpFax = corpFax;
	}

	public String getCorpFr() {
		return corpFr;
	}

	public void setCorpFr(String corpFr) {
		this.corpFr = corpFr;
	}

	public String getCorpHy() {
		return corpHy;
	}

	public void setCorpHy(String corpHy) {
		this.corpHy = corpHy;
	}

	public String getCorpName() {
		return corpName;
	}

	public void setCorpName(String corpName) {
		this.corpName = corpName;
	}

	public String getCorpPer() {
		return corpPer;
	}

	public void setCorpPer(String corpPer) {
		this.corpPer = corpPer;
	}

	public String getCorpPerFax() {
		return corpPerFax;
	}

	public void setCorpPerFax(String corpPerFax) {
		this.corpPerFax = corpPerFax;
	}

	public String getCorpPerMail() {
		return corpPerMail;
	}

	public void setCorpPerMail(String corpPerMail) {
		this.corpPerMail = corpPerMail;
	}

	public String getCorpPerPhone() {
		return corpPerPhone;
	}

	public void setCorpPerPhone(String corpPerPhone) {
		this.corpPerPhone = corpPerPhone;
	}

	public String getCorpPerTel() {
		return corpPerTel;
	}

	public void setCorpPerTel(String corpPerTel) {
		this.corpPerTel = corpPerTel;
	}

	public String getCorpPost() {
		return corpPost;
	}

	public void setCorpPost(String corpPost) {
		this.corpPost = corpPost;
	}

	public String getCorpSnxse() {
		return corpSnxse;
	}

	public void setCorpSnxse(String corpSnxse) {
		this.corpSnxse = corpSnxse;
	}

	public String getCorpTel() {
		return corpTel;
	}

	public void setCorpTel(String corpTel) {
		this.corpTel = corpTel;
	}

	public String getCorpZhce() {
		return corpZhce;
	}

	public void setCorpZhce(String corpZhce) {
		this.corpZhce = corpZhce;
	}

	public String getWsId() {
		return wsId;
	}

	public void setWsId(String wsId) {
		this.wsId = wsId;
	}

	public String getZpBday() {
		return zpBday;
	}

	public void setZpBday(String zpBday) {
		this.zpBday = zpBday;
	}

	public String getZpBmonth() {
		return zpBmonth;
	}

	public void setZpBmonth(String zpBmonth) {
		this.zpBmonth = zpBmonth;
	}

	public String getZpByear() {
		return zpByear;
	}

	public void setZpByear(String zpByear) {
		this.zpByear = zpByear;
	}

	public String getZpEday() {
		return zpEday;
	}

	public void setZpEday(String zpEday) {
		this.zpEday = zpEday;
	}

	public String getZpEmonth() {
		return zpEmonth;
	}

	public void setZpEmonth(String zpEmonth) {
		this.zpEmonth = zpEmonth;
	}

	public String getZpEyear() {
		return zpEyear;
	}

	public void setZpEyear(String zpEyear) {
		this.zpEyear = zpEyear;
	}

	public String getZpInfo() {
		return zpInfo;
	}

	public void setZpInfo(String zpInfo) {
		this.zpInfo = zpInfo;
	}

	public String getZpBdate() {
		return zpBdate;
	}

	public void setZpBdate(String zpBdate) {
		this.zpBdate = zpBdate;
	}

	public String getZpEdate() {
		return zpEdate;
	}

	public void setZpEdate(String zpEdate) {
		this.zpEdate = zpEdate;
	}

	public String getZpLeader() {
		return zpLeader;
	}

	public void setZpLeader(String zpLeader) {
		this.zpLeader = zpLeader;
	}

	public String getZpZyuan() {
		return zpZyuan;
	}

	public void setZpZyuan(String zpZyuan) {
		this.zpZyuan = zpZyuan;
	}

	public String getCType() {
		return cType;
	}

	public void setCType(String type) {
		cType = type;
	}

	public List getObjList() {
		return objList;
	}

	public void setObjList(List objList) {
		this.objList = objList;
	}

	public String getCType1() {
		return cType1;
	}

	public void setCType1(String type1) {
		cType1 = type1;
	}

	public String getExport() {
		return export;
	}

	public void setExport(String export) {
		this.export = export;
	}

	public boolean isCitySupervision() {
		return citySupervision;
	}

	public void setCitySupervision(boolean citySupervision) {
		this.citySupervision = citySupervision;
	}

	public boolean isReview() {
		return review;
	}

	public void setReview(boolean review) {
		this.review = review;
	}

	public int getIsSuanfei() {
		return isSuanfei;
	}

	public void setIsSuanfei(int isSuanfei) {
		this.isSuanfei = isSuanfei;
	}

	public TbDjpdCheck getCheck() {
		return check;
	}

	public void setCheck(TbDjpdCheck check) {
		this.check = check;
	}

	public Integer getCheckRole() {
		return checkRole;
	}

	public void setCheckRole(Integer checkRole) {
		this.checkRole = checkRole;
	}

}
